<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<base href="<%=basePath%>">
<%@ include file="/base/jsp/include.jsp"%>
<script type="text/javascript">
    var grid;
    var creditsFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length != 1) {
            parent.$.messager.w('请选择一条记录进行查看！');
            return;
        }
        var nickName="";
        if(rows[0].nickName!=null&&rows[0].nickName!=""){
            nickName=rows[0].nickName;
        }
        var url = sy.contextPath + '/go.do?path=user/userCreditLogList&id=' + rows[0].id;
        var dialog = parent.sy.modalDialog({
            title : '积分日志——'+nickName,
            width : 800,
            height : 620,
            url : url
        });
    };
    var delFun = function() {
        var rows = grid.datagrid('getSelections');
        if (rows.length == 0) {
            parent.$.messager.w('请选择需要删除的记录！');
            return;
        }
        parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
            if (r) {
                var ids = [];
                for ( var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    ids.push(r.id);
                }
                var id = ids.join(',');
                
                $.post(sy.contextPath + '/zxMessage/del.do', {
                    id : id
                }, function() {
                    rows.length = 0;//必须，否则有bug
                    grid.datagrid('reload');
                }, 'json');
            }
        });
    };
    $(function() {
        
        var menu;
        menu={
                url : sy.contextPath + '/zxMessage/list.do',
                toolbar : '#toolbar',
                singleSelect : false,
                fitColumns:true,
                columns : [ [ {
                    width : $(this).width() * 0.06,
                    title : '资讯标题',
                    field : 'zxTitle',
                    align : 'center'
                },{
                    width : $(this).width() * 0.06,
                    title : '发布人',
                    field : 'nickName',
                    align : 'center',
                    formatter : function(value, row, index){
                        return '<span href="javascript:void(0);">'+row.nickName+"("+row.account+")"+'</span>';
                    }
                },{
                    width : $(this).width() * 0.06,
                    title : '资讯内容',
                    field : 'content',
                    align : 'center',
                    formatter : function(value, row, index){
                        return '<a href="javascript:void(0);" title="点击查看详情" onclick="checkContent(\''+row.id+'\')">'+row.content+'</a>';
                    }
                },{
                    width : $(this).width() * 0.05,
                    title : '资讯类型',
                    field : 'type',
                    align : 'center',
                    formatter : function(value, row, index) {
                    	if(value == 0){
                    		return '发布';
                    	}else if(value == 1){
                    		return '转载';
                    	}
                    }
                },{
                    width : $(this).width() * 0.05,
                    title : '发布区域',
                    field : 'city',
                    align : 'center',
                },{
                    width : $(this).width() * 0.1,
                    title : '图片',
                    field : 'image',
                    align : 'center',
                    formatter:function(v){
                    	if (v)
                    		return po.showImg(v,18,18);
                    }
                }, {
                    width : $(this).width() * 0.1,
                    title : '创建时间',
                    field : 'createTime',
                    align : 'center',
                }, {
                    width : $(this).width() * 0.1,
                    title : '修改时间',
                    field : 'modifyTime',
                    align : 'center',
                }, {
                    width : $(this).width()*0.05,
                    title : '状态',
                    field : 'isAgree',
                    align : 'center',
                    formatter : function(value, row, index) {
                        if(value == 0){
                            return  '<a href="javascript:void(0);"  style="color:red" title="未审核">未审核</a>';
                        }else if(value == 1){
                            return  '<a href="javascript:void(0);"  ><img src="base/images/yes.png" title="审核通过" > </img></a>';
                        }else if(value == 2){
                            return  '<a href="javascript:void(0);"  ><img src="base/images/no.png" title="审核不通过" > </img></a>';
                        }
                    }
                }, {
                    width : $(this).width() * 0.1,
                    title : '设为轮播图',
                    field : 'becomeBanner',
                    align : 'center',
                    formatter : function(value, row, index){
                    	if(row.isIndexImage==0 || typeof(row.isIndexImage)=="undefined"){
                    		if(row.isAgree==1){
                    			return '<button onclick="becomeBanner(\''+row.id+'\');">设为首页轮播图</button>';
                    		}
                    		
                    	}else if(row.isIndexImage==1){
                    		return '<button onclick="notBecomeBanner(\''+row.id+'\');">取消首页轮播图</button>';
                    	}
                    	                    	
                    }
                }, {
                    width : $(this).width() * 0.05,
                    title : '轮播图照片',
                    field : 'bannerImages',
                    align : 'center',
                    formatter:function(value, row, index){
                    	if (value)
                    		return po.showImg(value,18,18);
                    }
                }, {
                    width : $(this).width() * 0.05,
                    title : '仅显示大图',
                    field : 'showImage',
                    align : 'center',
                    formatter:function(value, row, index){
                    	if(row.onlyShowImage == 1){
                    		return '<button onclick="notOnlyShowImage(\''+row.id+'\');">取消</button>';
                    	}
                    	if(row.isIndexImage==1){
                    		return '<button onclick="onlyShowImage(\''+row.id+'\');">仅显示大图</button>';
                    	}
                    	
                    }
                }, {
                    width : $(this).width() * 0.05,
                    title : '效果',
                    field : 'showImages',
                    align : 'center',
                    formatter:function(value, row, index){
                    	if(row.isIndexImage==1 && row.onlyShowImage ==1){
                    		return '<a href="javascript:void(0);"  ><img src="base/images/yes.png" title="仅显示大图" > </img></a>';
                    	}                    	
                    }
                }, {
                    width : $(this).width()*0.1,
                    title : '操作',
                    field : 'isAgrees',
                    align : 'center',
                    formatter : function(value, row, index) {
                    		if(row.isAgree == 1 || row.isAgree == 2){
                    			if(row.publishTime =='' || row.publishTime==null){
                    				return  '<a href="javascript:void(0);"  style="color:red" >已经审核过了！</a><button onclick = "tops(\''+row.isAgree+'\',\''+row.id+'\');">置顶</button>';
                    			}else{
                    				return  '<a href="javascript:void(0);"  style="color:red" >已经审核过了！</a><button onclick = "cancelTops(\''+row.isAgree+'\',\''+row.id+'\');">取消置顶</button>';
                    			}
                        		
                        	}else if(row.isAgree == 0){
                        		return '<a><button onclick="forbidden(1,\''+row.id+'\');">审核通过</button></a><a><button onclick="forbidden(2,\''+row.id+'\');">审核不通过</button></a>';
                        	}
                    }
                }
                ] ]
            };
        
        grid = $('#grid').datagrid(menu);
    });
    
    function forbidden(isAgree,id) {
          if(isAgree == 2){
            parent.$.messager.confirm('询问',"确定审核不通过吗？", function(r) {
                if (r) {
                    var data = {
                        id : id,
                        isAgree : 2
                    };
                    updateByNotAgreeReason(id);
                }
            });
        } else if(isAgree == 1){
            parent.$.messager.confirm('询问',"确定审核通过吗？", function(r) {
                if (r) {
                    var data = {
                        id : id,
                        isAgree : 1
                    };
                    SaveData(data);
                }
            });
        }
    }
    function SaveData(data) {
        var url = sy.contextPath + '/zxMessage/update.do';
        $.post(url, data, function() {
            grid.datagrid('reload');
        }, 'json');
    }

    function updateByNotAgreeReason(id){
        var url = sy.contextPath +'/go.do?path=zxMsg/notAgreeReason&id=' + id;
        var dialog = parent.sy.modalDialog({
            title : '审核不通过原因',
            width : 800,
            height : 620,
            url : url,
            buttons : [ {
                text : '确认',
                handler : function() {
                    dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
                }
            } ]
        });
   }
    
   function checkContent(id){
       var url = sy.contextPath +'/go.do?path=zxMsg/contentDetail&id=' + id;
       var dialog = parent.sy.modalDialog({
           title : '内容',
           width : 800,
           height : 620,
           url : url,
       });
   }
   
   function tops(isAgree,id){
	   if(isAgree==2){
		   $.messager.alert('Warning','审核未通过的不能置顶...');
		   return;
	   }
       var url = sy.contextPath + '/zxMessage/top.do';
       var data={
               id: id
       }
       $.post(url, data, function() {
           grid.datagrid('reload');
       }, 'json'); 
   }
   
   function cancelTops(isAgree,id){
	   if(isAgree==2){
		   $.messager.alert('Warning','审核未通过的不能置顶...');
		   return;
	   }
       var url = sy.contextPath + '/zxMessage/cancelTops.do';
       var data={
               id: id
       }
       $.post(url, data, function() {
           grid.datagrid('reload');
       }, 'json'); 
   }
   
   //设置为首页轮播图
   function becomeBanner(id){
	   var url = sy.contextPath +'/go.do?path=zxMsg/becomeBanner&id=' + id;
       var dialog = parent.sy.modalDialog({
           title : '设为首页轮播图',
           width : 800,
           height : 620,
           url : url,
           buttons : [ {
               text : '确认',
               handler : function() {
                   dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
               }
           } ]
       });
   }
   
 //取消设置为首页轮播图
   function notBecomeBanner(id){
	   var url=sy.contextPath + '/zxMessage/notBecomeBanner.do';
	   data={
			   id:id
	   }
	   $.post(url, data, function() {
           grid.datagrid('reload');
       }, 'json'); 
   }
   
 	function onlyShowImage(id){
 	   var url=sy.contextPath + '/zxMessage/onlyShowImage.do';
 	   data={
 			   id:id
 	   }
 	   $.post(url, data, function() {
            grid.datagrid('reload');
        }, 'json');
 	}
   
   function notOnlyShowImage(id){
 	   var url=sy.contextPath + '/zxMessage/notOnlyShowImage.do';
 	   data={
 			   id:id
 	   }
 	   $.post(url, data, function() {
            grid.datagrid('reload');
        }, 'json');
 	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
    <div id="toolbar" style="display: none;">
        <table>
            <tr>
                <td>
                    <table>
                        <tr>                          
                            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_delete',plain:true" onclick="delFun();">删除</a></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <form id="searchForm">
                        <table>
                            <tr>
                                <td>资讯标题：</td>
                                <td>
                                    <input type="text" class="easyui-textbox" name="name" style="width: 150px"  />
                                </td>
                                <td>
                                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
                                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
                                </td>
                            </tr>
                        </table>
                    </form>
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center',fit:true,border:false">
        <table id="grid" data-options="fit:true,border:false"></table>
    </div>
</body>
</html>